package com.demo.connectdbtest.module.common.util;
//
//import org.apache.commons.net.smtp.AuthenticatingSMTPClient;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.io.IOException;
//import java.security.InvalidKeyException;
//import java.security.NoSuchAlgorithmException;
//import java.security.spec.InvalidKeySpecException;
//
///**
// * 描述：
// *
// * @author: chengc
// * @date 2021/03/31
// */
public class SMTPClientUtils {
//
//    private static final Logger log = LoggerFactory.getLogger(SMTPClientUtils.class);
//    private static final String domain = "@hzsunlive.com,@imdawei.cn";
//
//    public static boolean auth(String username, String password) {
//        if (!username.contains("@")) {
//            username = username + domain;
//        } else if (username.indexOf("@hzsunlive.com") != -1) {
//            log.info("auth-fail,username={}", username);
//            return false;
//        }
//        AuthenticatingSMTPClient client = new AuthenticatingSMTPClient("TLS", true);
//        client.setDefaultTimeout(10 * 1000);
//        try {
//            client.connect("smtp.exmail.qq.com", 465);
//            client.ehlo("localhost");
//            client.auth(AuthenticatingSMTPClient.AUTH_METHOD.LOGIN, username, password);
//            if (client.getReplyCode() == 235) {
//                log.info("smtp-auth-success,reply={}", client.getReplyString());
//                return true;
//            } else {
//                log.info("smtp-auth-failed,reply={}", client.getReplyString());
//                return false;
//            }
//        } catch (IOException | NoSuchAlgorithmException | InvalidKeySpecException | InvalidKeyException e) {
//            log.error("smtp-auth-failed", e);
//            return false;
//        } finally {
//            if (client.isConnected()) {
//                try {
//                    client.disconnect();
//                } catch (IOException f) {
//                    // do nothing
//                }
//            }
//        }
//    }
}
